import { createRouter, createWebHashHistory } from 'vue-router';
import Layout from '@/Layouts/index.vue';
// import i18n from '@/locales';
// const { global } = i18n;
export const constantRoutes = [
  {
    path: '/login',
    name: 'Login',
    component: () => import('@/views/login/index.vue'),
    meta: {
      title: '登录',
    },
    hidden: true,
  },
  {
    path: '/401',
    name: '401',
    component: () => import('@/views/errorPage/401.vue'),
    hidden: true,
  },
  {
    path: '/404',
    name: '404',
    component: () => import('@/views/errorPage/404.vue'),
    hidden: true,
  }
];

export const asyncRoutes = [
  {
    path: '/',
    component: Layout,
    redirect: '/index',
    name: 'Root',
    children: [
      {
        path: '/index',
        name: 'Index',
        component: () => import('../views/index/index.vue'),
        meta: {
          title: '首页',
          icon: 'icon-home',
          affix: true,
          noKeepAlive: true,
        },
      },
    ],
  },
  {
    path: "/count",
    component: Layout,
    redirect: "/count/index",
    meta: {
      title: "数据统计",
      svgIcon: "unocss",
      alwaysShow: true // 将始终显示根菜单
    },
    children: [
      {
        path: "load",
        component: () => import("@/views/count/load.vue"),
        name: "countLoad",
        meta: {
          title: "销售统计",
          keepAlive: true
        }
      }
    ]
  },
  {
    path: "/purchase",
    component: Layout,
    redirect: "/purchase/order",
    meta: {
      title: "采购管理",
      svgIcon: "unocss",
      alwaysShow: true // 将始终显示根菜单
    },
    children: [
      {
        path: "order",
        component: () => import("@/views/purchase/order.vue"),
        name: "purchaseOrder",
        meta: {
          title: "采购列表",
          keepAlive: true
        }
      },
      {
        path: "order_detail",
        component: () => import("@/views/purchase/order_detail.vue"),
        name: "purchaseOrderDetail",
        meta: {
          title: "采购清单",
          keepAlive: true,
          alwaysShow:false,
        }
      },
    ]
  },
  {
    path: "/prodcut",
    component: Layout,
    redirect: "/product/index",
    meta: {
      title: "商品管理",
      svgIcon: "unocss",
      alwaysShow: true // 将始终显示根菜单
    },
    children: [
      {
        path: "index",
        component: () => import("@/views/product/product.vue"),
        name: "productIndex",
        meta: {
          title: "商品列表",
          keepAlive: true,
        }
      },
      {
        path: "spec",
        component: () => import("@/views/product/product_spec.vue"),
        name: "productSpec",
        meta: {
          title: "商品规格",
          keepAlive: true
        }
      },
      {
        path: "inventory",
        component: () => import("@/views/product/inventory.vue"),
        name: "productInventory",
        meta: {
          title: "商品库存",
          keepAlive: true
        }
      },
    ]
  },
  {
    path: "/system",
    component: Layout,
    redirect: "/system/user",
    meta: {
      title: "系统管理",
      svgIcon: "unocss",
      alwaysShow: true // 将始终显示根菜单
    },
    children: [
      {
        path: "user",
        component: () => import("@/views/system/user.vue"),
        name: "systemUser",
        meta: {
          title: "用户管理",
          keepAlive: true
        }
      },
      {
        path: "vendor",
        component: () => import("@/views/system/vendor.vue"),
        name: "systemVendor",
        meta: {
          title: "营销商管理",
          keepAlive: true
        }
      },
      {
        path: "supplier",
        component: () => import("@/views/system/supplier.vue"),
        name: "systemSupplier",
        meta: {
          title: "供货商管理",
          keepAlive: true
        }
      },
      {
        path: "warehouse",
        component: () => import("@/views/system/warehouse.vue"),
        name: "systemWarehouse",
        meta: {
          title: "仓库管理",
          keepAlive: true
        }
      }
    ]
  }
  // {
  //   path: '/comp',
  //   component: Layout,
  //   name: 'Comp',
  //   meta: { title: '组件', icon: 'icon-code' },
  //   children: [
  //     {
  //       path: '/element',
  //       name: 'ElementComp',
  //       component: () => import('@/views/element/index.vue'),
  //       meta: {
  //         title: '图标',
  //         icon: 'icon-code',
  //       },
  //     },
  //     {
  //       path: '/iconPark',
  //       name: 'IconPark',
  //       component: () => import('@/views/icon/index.vue'),
  //       meta: {
  //         title: 'IconPark',
  //         icon: 'icon-like',
  //       },
  //     },
  //     {
  //       path: '/chart',
  //       name: 'Chart',
  //       component: () => import('@/views/echarts/index.vue'),
  //       meta: {
  //         title: '图标',
  //         icon: 'icon-chart-line',
  //       },
  //       children: [
  //         {
  //           path: '/line',
  //           name: 'Line',
  //           component: () => import('@/views/echarts/line.vue'),
  //           meta: {
  //             title: '线条',
  //           },
  //         },
  //         {
  //           path: '/bar',
  //           name: 'Bar',
  //           component: () => import('@/views/echarts/bar.vue'),
  //           meta: {
  //             title: 'Bar',
  //           },
  //         },
  //         {
  //           path: '/otherChart',
  //           name: 'OtherChart',
  //           component: () => import('@/views/echarts/other.vue'),
  //           meta: {
  //             title: 'OtherChart',
  //           },
  //         },
  //       ],
  //     },
  //   ],
  // },
  // {
  //   path: '/errorPage',
  //   name: 'ErrorPage',
  //   component: Layout,
  //   meta: {
  //     title: 'ErrorPage',
  //     icon: 'icon-link-cloud-faild',
  //   },
  //   children: [
  //     {
  //       path: '/404Page',
  //       name: '404Page',
  //       component: () => import('@/views/errorPage/404.vue'),
  //       meta: {
  //         title: '404Page',
  //         icon: 'icon-link-cloud-faild',
  //       },
  //     },
  //     {
  //       path: '/401Page',
  //       name: '401Page',
  //       component: () => import('@/views/errorPage/401.vue'),
  //       meta: {
  //         title: '401Page',
  //         icon: 'icon-link-interrupt',
  //       },
  //     },
  //   ],
  // },
  // {
  //   path: '*',
  //   redirect: '/404',
  //   hidden: true,
  // },
];

// 合并路由
const router = createRouter({
  history: createWebHashHistory(),
  routes: constantRoutes,
});

// reset router
export function resetRouter() {
  router.getRoutes().forEach((route) => {
    const { name } = route;
    if (name) {
      router.hasRoute(name) && router.removeRoute(name);
    }
  });
}

export default router;
